﻿<%@ WebHandler Language="C#" Class="buildingInfo" %>

using System;
using System.Web;
using System.Text;

public class buildingInfo : AjaxHandlerBase 
{

    override public void RequestProcess(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.AddHeader("pragma", "no-cache");
        context.Response.AddHeader("cache-control", "");
        context.Response.CacheControl = "no-cache";
        
        string strType = context.Request["type"];
        string strCommunityId = context.Request["CommunityId"];

        if (string.IsNullOrEmpty(strCommunityId)) { context.Response.Write(""); return; }

        string strReuslt = "";
        switch (strType.ToLower())
        {
            case "datadic"://根据Key获取数据字典中相应的字典项目
                strReuslt = GetBuildingInfo(strCommunityId);
                break;
            default:
                break;
        }

        context.Response.Write(strReuslt);
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }


    /// <summary>
    /// 根据Key获取数据字典中相应的字典项目
    /// </summary>
    /// <param name="strKey"></param>
    /// <returns></returns>
    private string GetBuildingInfo(string strCommunityId)
    {
        System.Collections.Generic.List<Chenxin.Lib.House.Entity.Community_BuildingInfo> buildingInfoList = new System.Collections.Generic.List<Chenxin.Lib.House.Entity.Community_BuildingInfo>();

        //根据楼盘ID取得对应的楼栋信息
        string strWhere = string.Format("CommunityId = '{0}'", strCommunityId);
        buildingInfoList = Chenxin.Lib.House.DAL.Community_BuildingInfo.GetListArray(strWhere, "BuildingName");        

        //生成JSON字符串
        StringBuilder str = new StringBuilder();

        foreach (Chenxin.Lib.House.Entity.Community_BuildingInfo item in buildingInfoList)
        {
            StringBuilder strval = new StringBuilder();

            strval.Append("{");
            strval.Append(" BuildingId: '" + item.BuildingId + "',");
            strval.Append(" Floor: '" + item.Floor + "',");
            strval.Append(" RoomRule: '" + item.RoomRule + "'");
            strval.Append(" }");

            
            str.Append(", {");
            str.Append(" txt: \"" + item.BuildingName + "\", ");
            str.Append(" val: \"" + strval.ToString() + "\"");
            
            
            str.Append(" }");
        }

        return str.ToString();
    }
}